<?php

namespace App\Http\Controllers;

use App\Http\Resources\CelueCollection;
use App\Http\Resources\CelueResource;
use Illuminate\Http\Request;

class CelueController extends Controller
{
    public function celueType()
    {
        $data = \App\Models\CelueType::all();
        return [
            'code' => 200,
            'message' => '请求成功',
            'data' => $data
        ];
    }

    public function list(Request $request)
    {
        $type = $request->input('type');
        $pageSize = $request->input('page_size', 10);
        $data = \App\Models\Celue::where('celue_type_id', $type)
            ->orderBy('id','desc')
            ->paginate($pageSize);
        return new CelueCollection($data);
    }

    public function detail(Request $request)
    {
        $id = $request->input('id');
        $data = \App\Models\Celue::where('is_display', 1)->where('id', $id)->firstOrFail();
        $data->view_num=$data->view_num+1;
        $data->save();
        return new CelueResource($data);
    }
}
